/*
*   EMSGeneralUtils.h
*   EVE Mac Suite
* 
*   Created by Vadim Lozko on 2/4/09.
*   Copyright 2009 __Vadim__. All rights reserved.
* 
*/

@class EMSCharacterViewController;

//#define DEBUG												0


#define EVECDContext										[[EVEAPICoreDataController coreDataController] managedObjectContext]

#define APP_NAME											@"EVE Mac Suite"

#define CORE_DATA_STORE_NAME								@"EVEMacSuiteDataStore"
#define CORE_DATA_STORE_FULL_NAME							CORE_DATA_STORE_NAME//[CORE_DATA_STORE_NAME stringByAppendingString:@".xml"]

#define	SKILL_NAME_KEY										@"name"
#define SKILL_RANK_KEY										@"rank"
#define SKILL_DESC_KEY										@"description";
#define CURR_LEVEL_KEY										@"level"
#define LEARNED_POINTS_KEY									@"skillPointsLearned"

#define DISPLAY_INFO_DICT_TYPE_KEY							@"type"
#define DISPLAY_INFO_DICT_CHARACTER							@"character"
#define DISPLAY_INFO_DICT_SKILL_IN_TRAINING_FINISH_DATE		@"skillInTrainingFinishDate"
#define DISPLAY_INFO_DICT_SKILL_IN_TRAINING_TIME_TO_TRAIN	@"skillInTrainingTimeToTrain"
#define DISPLAY_INFO_DICT_SKILL_IN_TRAINING_NAME			@"skillInTrainingName"
#define DISPLAY_INFO_DICT_LEARNED_SKILL_TYPE				@"learnedSkill"
#define DISPLAY_INFO_DICT_LEARNED_GROUP_TYPE				@"learnedGroup"

#define CHAR_INFO_DICT_NAME									@"name"
#define CHAR_INFO_DICT_CHARID								@"charID"
#define CHAR_INFO_DICT_CORP									@"corp"
#define CHAR_INFO_DICT_CORPID								@"corpID"
#define CHAR_INFO_DICT_USERID								@"userID"
#define CHAR_INFO_DICT_APIKEY								@"apiKey"
#define CHAR_INFO_DICT_PIXELSIZE							@"pixelSize"

#define DOWNLOADER_QUEUE_CHECK_FREQUENCY					1.0
#define DOWNLOADER_RETRY_ATTEMPTS							3

#define USER_DEFAULTS_CHARACTERS_KEY						@"Characters"
#define USER_DEFAULTS_PREFERED_CHARACTER_KEY				@"PreferedCharacter"

#define SKILL_PLANNER_SKILL_AND_LEVEL_DRAGGED_TYPE			@"SkillPlannerSkillAndLevelDraggedType"

#define SKILL_TREE_API_TYPE									@"SkillTree"
#define SERVER_STATUS_API_TYPE								@"ServerStatus"
#define CHARACTER_SHEET_API_TYPE							@"CharacterSheet"
#define CHARACTER_SKILL_IN_TRAINING_API_TYPE				@"SkillInTraining"
#define CHARACTER_SKILL_QUEUE_API_TYPE						@"SkillQueue"

#define NOTIFICATION_SUCCESS_UPDATE_KEY						@"success"
#define NOTIFICATION_SKILL_IN_TRAINING_OBJECTID_KEY			@"SkillInTrainingID"

#define WILL_UPDATE_SKILL_TREE_NOTIFICATION_NAME			@"SkillTreeWillUpate"
#define DID_UPDATE_ALL_CHARACTERS_NOTIFICATION_NAME			@"DidUpdateAllCharacters"
#define WILL_UPDATE_LEARNED_SKILLS_NOTIFICATION_NAME		@"CharacterSheetWillUpdate"
#define SKILL_IN_TRAINING_DID_FINISH_NOTIFICATION			@"SkillTrainingFinished"

@protocol EVEAPIDataHandler

@property(assign) id delegate;
-(NSManagedObjectContext*)managedObjectContext;
-(NSString*)APIDocumentType;
-(NSString*)xmlStorePath;
-(NSDictionary*)downloaderInfo;
-(void)updateCoreDataStore;
-(void)verifyCoreDataStore;
-(void)update;
-(void)forceUpdate;
-(BOOL)cachedDataCurrent;
-(BOOL)xmlDocValid:(NSXMLDocument*)document;
-(void)downloadLatestXMLDoc;
-(void)downloadRequestDidFinishForXMLDoc:(NSXMLDocument*)document;
-(void)downloadRequestDidFailWithError:(NSError*)error;
-(void)documentDidDownload:(BOOL)success;
-(void)updateDidFinish:(NSNumber*)success;
-(void)startUpdateTimer;
-(void)invalidateTimers;
@end

@protocol EMSCharactersWindowControllerDelegate <NSObject>

-(void)createNewCharacterFromInfo:(NSDictionary*)infoDict;
-(void)addNewCharacterWindowDidCancel;

@end

@protocol EMSCharacterViewControllerDelegate <NSObject>

-(void)didLoadCharacterViewController:(EMSCharacterViewController*)controller;

@end


@interface EMSGeneralUtils : NSObject

+(NSString* )applicationSupportFolder;
+(NSDictionary*)urlConstants;
+(void)setHyperlinkWithTextField:(NSTextField*)inTextField text:(NSString*)text URL:(NSURL*)url;
+(void)showNoInternetConnectionAlertWithMessage:(NSString*)message;
+(NSArray*)nameSortDescriptors;
+(NSArray*)positionSortDescriptors;
+(NSArray*)levelSortDescriptors;
@end

@interface NSManagedObjectContext (ConvenienceAdditions)

-(NSSet*)fetchObjectsForEntityName:(NSString *)newEntityName
					 withPredicate:(id)stringOrPredicate, ...;
-(NSArray*)fetchObjectsForEntityName:(NSString *)newEntityName
					 sortDescriptors:(NSArray*)sortDescriptors
					   withPredicate:(id)stringOrPredicate, ...;
-(id)fetchObjectForEntityName:(NSString *)newEntityName
				withPredicate:(id)stringOrPredicate, ...;
@end

@interface NSTreeNode (ConvenienceAdditions)

-(NSInteger)treeSize;
-(NSInteger)treeDepth;
-(NSInteger)treeWidth;
-(NSInteger)nodesToLevel:(NSInteger)level;
-(NSInteger)nodesAtLevel:(NSInteger)level;
@end


@interface NSAttributedString (Hyperlink)
+(id)hyperlinkFromString:(NSString*)inString withURL:(NSURL*)aURL;
@end

